#业务类：登录业务
import allure

#导入和该业务有关的页面类
from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

class ServiceLogin(object):
    def __init__(self,driver,base_url):
        #定义页面有关的页面对象
        self.page_index=PageIndex(driver,base_url)
        self.page_login=PageLogin(driver,base_url)
        self.page_user=PageUser(driver,base_url)

    def service_login_001(self,d):
        # 下面是操作UI1：首页
        allure.attach("","步骤1：打开首页")
        self.page_index.openUrl()
        allure.attach("", "步骤2：点击首页上的登录按钮")
        self.page_index.click_login()

        # 下面是操作UI2：登录页
        allure.attach("", f"步骤3：输入账号:{d['zanhao']}")
        self.page_login.input_zanhao(d["zanhao"])
        allure.attach("", f"步骤4：输入密码:{d['pwd']}")
        self.page_login.input_pwd(d["pwd"])

        self.page_login.click_login()


        # 下面是操作UI3：个人中心页
        imgName=self.page_user.savePng3("登录",d["key"]) #"登录_K001_20250507195304"
        allure.attach(open(file=f"./screen/{imgName}.png",mode="rb").read(), "登录之后的截图",allure.attachment_type.PNG)
        siji=self.page_user.getNicenText() #"nswe，欢迎光临"

        return d["yuqi"] in siji

    def service_login_002(self,d):
        # 下面是操作UI1：首页
        self.page_index.openUrl()
        self.page_index.click_login()

        # 下面是操作UI2：登录页
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        siji=self.page_login.getErrorTipText() #"账号或密码错误"

        return d["yuqi"] in siji

    def service_login_003(self,d):
        # 下面是操作UI1：首页
        self.page_index.openUrl()
        self.page_index.click_login()

        # 下面是操作UI2：登录页
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        siji=self.page_login.getZanhaoClassAttr() #"input_text         invalid-text"
        return d["yuqi"] in siji

    def service_login_004(self,d):
        # 下面是操作UI1：首页
        self.page_index.openUrl()
        self.page_index.click_login()

        # 下面是操作UI2：登录页
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_login()
        siji=self.page_login.getPwdClassAtrr() #"input_text         invalid-text"
        return d["yuqi"] in siji

